<?php

namespace App\Models\Page;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class PageStyle
 * @package App\Models\Page
 * @version August 9, 2018, 11:16 am CST
 *
 * @property \App\Models\Page\Pagetpl pagetpl
 * @property string name
 * @property string title
 * @property integer pagetpl_id
 * @property string subtitle
 * @property string ui
 */
class PageStyle extends Model
{
    use SoftDeletes;

    public $table = 'page_styles';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'name',
        'title',
        'pagetpl_id',
        'subtitle',
        'ui',
        'mark',
        'bg',
        'background',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name'       => 'string',
        'title'      => 'string',
        'pagetpl_id' => 'integer',
        'subtitle'   => 'string',
        'ui'         => 'string',
        'mark'       => 'string',
        'bg'         => 'string',
        'background' => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'name' => 'required|max:100',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function pagetpl()
    {
        return $this->hasOne(\App\Models\Application\Pagetpl::class, 'id', 'pagetpl_id');
    }

    /**
     * 样式素材管理
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     **/
    public function pageIcons()
    {
        return $this->hasMany(\App\Models\Page\PageIcon::class, 'page_style_id', 'id');
    }

}
